<template>
  <ul>
    <li
      @click.prevent="goToDetail(item)"
      v-for="(item, index) in items"
      :key="index"
    >
      <div class="content">
        <span class="font">
          {{ item["标题"] }}
        </span>
        <span class="i">
          {{ item.time }}
        </span>
      </div>
    </li>
  </ul>
</template>
<script>
export default {
  name: "list",
  props: {
    items: {
      type: Array,
    },
  },
  watch: {
    items: {
      handler(n, o) {  
        for(var k in n) {
          n[k]["time"] = myReplace (n[k].收藏时间.split(" ")[0],"/","-");
        } 
        // 用正则表达式进行替换的方法
        function myReplace(sInput,sChar,sReplaceChar) {
            if(sInput==""||sInput==undefined) {
                return "";
            }
            var oReg =new RegExp(sChar,"g");
            return sInput.replace(oReg, sReplaceChar);
        }
      },
      immediate: true, //刷新加载 立马触发一次handler
      deep: true, // 可以深度检测到 items 对象的属性值的变化
    },
  },
  data() {
    return {};
  },
  mounted() {},
  methods: {
    goToDetail(item) {
      let type = 1;
      let url = ""; 
      let data = JSON.stringify({
        dbcode: item.数据库代码 + "_METADATA",
        sysid: item.资源ID,
        fileName:item.文件名,
        dbname:item.来源数据库,
        vsm:item.SYS_VSM,
      });
      let ary = [
        "期刊",
        "博士",
        "硕士",
        "国内会议",
        "国际会议",
        "报纸",
        "年鉴",
        "中国专利",
        "海外专利",
        "国家标准",
        "行业标准",
        "中国标准",
        "国外标准",
        "成果",
        "法律法规",
        "工具书",
      ];
      ary.forEach((i) => {
        switch (item.资源来源数据库) {
          case i:
            type = 2;
            url =
              window.localStorage.mirrorUrl+
              item.资源库代码 +
              "&filename=" +
              item.资源文件名;
            break;
        }
      });
      if(type === 2) {
        this.$router.push({
            path: "/cnkiDetail",
            query: {
              type,
              data,
              url,
              tableName:item.表名,
              name: item.题名,
            }
        })
      }else {
        this.$router.push({
            path: "/detail",
            query: {
              type,
              data,
              url,
              tableName:item.表名,
              name: item.题名,
            }
        })
      }
    },
  },
};
</script>
<style lang="scss" scoped>
@import "../../assets/css/zyy_phone.css";
@import "../../assets/css/search.css";
.list-header {
  min-height: calc(100vh - 120px);
  background: #fff;
  overflow-x: hidden;
  ul {
    width: 100%;
    min-height: calc(100vh - 120px);
    li {
      width: 100%;
      height: 40px;
      line-height: 40px;
      border-bottom: 1px solid #ddd;
      padding: 0 10px;
      .img {
        display: inline-block;
        width: 32px;
        height: 32px;
        img {
          width: 100%;
          height: 100%;
        }
      }
      .content {
        display: inline-block;
        height: 100%;
        vertical-align: top;
        width: calc(100% - 20px);
        position: relative;
        // margin-bottom: 20px;
        // margin-top: 20px;
        .font {
          width: calc(100% - 100px);
          overflow: hidden;
          text-overflow: ellipsis;
          white-space: nowrap;
          font-size: 14px;
          display: inline-block;
          font-weight: 600;
        }
        .i {
          position: absolute;
          right: 0;
          width: 100px;
          text-align: right;
          color: #989898;
        }
      }
      .recommond {
        font-size: 14px;
        margin-top: 5px;
        color: #868686;
      }
    }

    li:nth-child(1) {
      margin-top: 10px;
    }

    li:last-child {
      margin-bottom: 0;
    }
  }
}
</style>